var pageIds = new Array('news', 'search', 'weather', 'my');

function dragHandler(index) {
	if(index < pageIds.length - 1) {
		swipLeftHandler(index);
	}
	if(index > 0) {
		swipRightHandler(index);
	}
}

/**
 * 当前页面向左划动，切换Tab
 */
function swipLeftHandler(index) {
	var _self = plus.webview.currentWebview();
	var _next = plus.webview.getWebviewById(pageIds[index + 1] + '.html');
	var _index = plus.webview.getLaunchWebview();
	_self.drag({
		direction: 'left', //滑动方向
		moveMode: 'followFinger'
	}, {
		view: _next,
		moveMode: "follow"
	}, function(e) {
		if(e.type == 'end' && e.result) {
			_index.evalJS('h("#footer-Menu").find("a").removeClass("mui-active");h("#' + pageIds[index + 1] + '").addClass("mui-active");');
			_index.evalJS('changeTitle(titleStrs['+(index+1)+'])');
			if(index == 0)
				_index.evalJS('document.getElementById("hrmbtn").style.display = "none";');
		}
	});
}

/**
 * 当前页面向右划动，切换Tab
 */
function swipRightHandler(index) {
	var _self = plus.webview.currentWebview();
	var _index = plus.webview.getLaunchWebview();
	var _prev = plus.webview.getWebviewById(pageIds[index - 1] + '.html');
	if(index == 1) {
		_prev = plus.webview.getSecondWebview();
	}
	_self.drag({
		direction: 'right', //滑动方向
		moveMode: 'followFinger'
	}, {
		view: _prev,
		moveMode: "follow"
	}, function(e) {
		if(e.type == 'end' && e.result) {
			_index.evalJS('h("#footer-Menu").find("a").removeClass("mui-active");h("#' + pageIds[index - 1] + '").addClass("mui-active");');
			_index.evalJS('changeTitle(titleStrs['+(index-1)+'])');
			if(index == 1)
				_index.evalJS('document.getElementById("hrmbtn").style.display = "";');
		}
	});
}